<?php
/*
 * Qua trinh hoc van
 */
?>

<legend id="step2" class='title-field title-jobs mt_20'><i class='icon icon-plus-sign mt_5 icon-white'></i> Quá trình học vấn</legend>
<div class='info-job'>
    <!-- list qua trinh hoc van -->
    <?php if (count($model) > 0 && is_array($model)) { ?>
        <?php foreach ($model as $key => $item) { ?>
            <div class="row-fluid row-quatrinh item-<?php echo $hid . '-' . $item->id; ?>">
                <div class='span3 ml10'>
                    Năm tốt nghiệp<br />
                    <b><?php echo $item->totnghiep_thang . '/' . $item->totnghiep_nam; ?></b>

                </div>
                <div class='span4'>
                    <span class='truong'>
                        <?php echo ucwords($item->truong_khoahoc); ?></span> - <span class='tp-bc'>
                        <?php echo $item->thanhpho . ', ' . $item->quocgia . ', ' . $item->bangcap->name; ?>
                    </span><br />
                    <span class='mota'>
                        <?php echo $item->tomtat; ?>
                    </span>
                </div>
                <div class='span4 align-right'>
                    <a href="#" class='edit' prop="<?php echo $hid . '-' . $item->id; ?>"><i class="icon-pencil"></i> Sửa</a>
                    <a href="#" class='delete'prop="<?php echo $hid . '-' . $item->id; ?>" ><i class="icon-trash"></i> Xóa</a>
                </div>
            </div>
        <?php } ?>
        <div class='row-fluid'>
            <div class='span3'>&nbsp;</div>
            <div class='span9'>
                <a href="#" class='add btn btn-info mt_20' prop="<?php echo $hid . '-' . $item->id; ?>"><i class="icon-pencil"></i> Thêm</a>
            </div>
        </div>
    <?php } else { ?>
    <!-- end list qua trinh hoc van -->
        <?php
        $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'quatrinhhocvan-form',
            'type' => 'horizontal',
            'action' => Yii::app()->getBaseUrl(true) . '/ungvien/tintimviec.html' . $hid > 0 ? '?id=' . $hid . '#step2' : '',
            'enableClientValidation' => true,
            //'enableAjaxValidation' => true,
            'clientOptions' => array(
                'validateOnSubmit' => true,
            ),
                ));
        ?>
        
        <?php echo $form->textFieldRow($model, 'truong_khoahoc', array('class' => 'span4')); ?>
        <?php echo $form->textFieldRow($model, 'thanhpho', array('class' => 'span4')); ?>
        <?php echo $form->textFieldRow($model, 'quocgia', array('class' => 'span4')); ?>
        <?php echo $form->dropDownListRow($model, 'bangcap_id', CHtml::listData(Bangcap::model()->findAllByAttributes(array('published' => 1)), 'id', 'name'), array('prompt' => '- Chọn -', 'class' => 'span4')); ?>
        <div class='div-row'>
            <label class='w150'>Thời gian tốt nghiệp:</label>
            <p class='nn-row' style='margin-top:-3px;'>
                Tháng: <input type='text' name='Quatrinhhocvan[thang]' class='span1 ar' onkeyup="BlockChar(this,'NotNumbers')" />
                Năm: <input type='text' name='Quatrinhhocvan[nam]' class='span1 ar' onkeyup="BlockChar(this,'NotNumbers')" />
            </p> 
        </div>
        <?php echo $form->textAreaRow($model, 'tomtat', array('class' => 'span7 clearfix')); ?>
        <div class='control-group showsub count'>
            (Mục tiêu nghề nghiệp không được quá <input id='ktt' value='2000' class='span1' /> kí tự)
        </div>
        <div class='div-row'>
            <label class='mt w150'>&nbsp;</label>
            <p class='nn-row'>
                <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'id' => 'btn-action', 'label' => 'Cập nhật', 'icon' => 'icon-refresh icon-white')); ?>
                <?php $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'reset', 'type' => 'primary', 'label' => 'Bỏ qua', 'icon' => 'icon-remove-sign icon-white', 'htmlOptions' => array('class' => 'close-form'))); ?>
            </p> 
        </div>

        <div class='clearfix'></div>
        <?php $this->endWidget(); ?>
    <?php } ?>
</div>

<script>
    $(document).ready(function(){
        //add
        $("a.add").click(function(e) {
            $.post('<?php echo Yii::app()->getBaseUrl(true); ?>/ungvien/tintimviec/addquatrinhhocvan.html<?php if ($hid != '') { echo '?id=' . $hid . '#step2';}    ?>',{action: 'addquatrinhhoc'},
            function(data){
                bootbox.alert(data);
            });
            e.preventDefault();
        });
        //edit
        $("a.edit").click(function(e) {
            var _prop = $(this).attr('prop');
            $.post('<?php echo Yii::app()->getBaseUrl(true); ?>/ungvien/tintimviec/editquatrinhhoc?data='+_prop,{action: 'editquatrinhhoc'},
            function(data){
                bootbox.alert(data);
            });
            e.preventDefault();
        });
        //delete
        $("a.delete").click(function(e) {
            var t = $(this)
            bootbox.confirm('Bạn chắc có muốn xóa!!!','Bỏ qua','Xóa',function(result){
                if(result){
                    var _prop = t.attr('prop');
                    $.post('<?php echo Yii::app()->getBaseUrl(true); ?>/ungvien/tintimviec/delquatrinhhoc?data='+_prop,{action: 'delquatrinhhoc'},
                    function(data){
                        bootbox.alert(data);
                        $('.item-'+_prop).remove();
                    });
                }
            });
            e.preventDefault();
        });
        /* tom tat qua trinh hoc */
        $('#Quatrinhhocvan_tomtat').keyup(function(){
            var mtss = $(this).val();
            if(mtss.length > 2000){
                alert('Nhập không quá 2000 từ');
                var a = mtss.substr(0,2000);
                $('#ktt').val(a);
                return false;
            }else{
                $('#ktt').val(2000-mtss.length);
            }
                
        });
    });
</script>